package com.yuefresh.dish;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 * 
 * @Description: 饭店控制类
 * @author junhao
 * @since 2013-3-17 下午15:29:25 
 */
@Controller
@RequestMapping("/issue")
public class RestaurantController {
	private final static Logger logger = LoggerFactory.getLogger(RestaurantController.class);
	
	@Autowired private RestaurantManager restaurantManager;
	
	
	/**
	 * 注册饭店
	 */
	@RequestMapping(params="m=register")
	public ModelAndView register(HttpServletRequest request) {
		logger.info("饭店注册");
		Restaurant restaurant = new Restaurant();
		//restaurant.setCompany(company)
		//饭店是公司保存后的下一步，先登记公司，再在公司上登记饭店，一个登陆用户只能有一个注册公司
		restaurant.setName(request.getParameter("name"));
		restaurant.setCity(request.getParameter("city"));
		restaurant.setProvince(request.getParameter("province"));
		restaurant.setAddress(request.getParameter("address"));
		restaurant.setDescription(request.getParameter("description"));
		
		restaurantManager.register(restaurant);
		
		ModelAndView mv = new ModelAndView("redirect:" + "restaurant_success");
		
		return mv;
	}
	
	/**
	 * 更新饭店信息
	 */
	@RequestMapping(params="m=update")
	public ModelAndView update(HttpServletRequest request) {
		logger.info("饭店审核通过");
		Restaurant restaurant = new Restaurant();
		//restaurant.setCompany(company)
		//饭店是公司保存后的下一步，先登记公司，再在公司上登记饭店，一个登陆用户只能有一个注册公司
		restaurant.setName(request.getParameter("name"));
		restaurant.setCity(request.getParameter("city"));
		restaurant.setProvince(request.getParameter("province"));
		restaurant.setAddress(request.getParameter("address"));
		
		restaurantManager.register(restaurant);
		
		ModelAndView mv = new ModelAndView("redirect:" + "restaurant_success");
		
		return mv;
	}
}
